import { maxDisplayWidth, unitPrecision, viewportWidth } from "@/global";

export const pxChangeVw = (
  px: string | number | undefined,
  isNumber = false
) => {
  px = parseFloat(px as string);
  const innerWidth = window.innerWidth;
  if (innerWidth >= maxDisplayWidth)
    return (
      Math.round(
        ((px * maxDisplayWidth) / viewportWidth) * 10 ** unitPrecision
      ) /
        10 ** unitPrecision +
      "px"
    );
  const value =
    Math.round(((px * 100) / viewportWidth) * 10 ** unitPrecision) /
    10 ** unitPrecision;
  return isNumber ? value : value + "vw";
};

export const getImg = (str: string) => {
  return new URL(`../assets/images/${str}`, import.meta.url).href;
};

export const getIcon = (str: any) => {
  return new URL(`../assets/icons/${str}`, import.meta.url).href;
};
